﻿﻿<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>配套单校准</title>
  <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
  <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
  <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
  <style>
    .inline-block {
      display: inline-block;
    }

    .divLabel {
      margin-bottom: 5px;
    }

    /* 重写下拉框样式 */
    .select {
      width: 200px;
    }

    .combobox-item {
      height: 32px;
    }

    /* 重写日期框样式 
    .datebox {
      height: 24px !important;
      line-height: 24px !important;
    }*/

    /* 重写文本框样式 */
    #queryZone .textbox-text,
    #dialogQueryZone .textbox-text,
    #processZone .textbox-text {
      line-height: 22px !important;
      height: 22px !important;
    }


    .container {
      width: 100%;
      font-size: 0;
    }

    .left {
      display: inline-block;
      width: 40%;
      height: 300px;
      padding-right: 10px;
    }

    .right {
      display: inline-block;
      /* 右侧宽度 = 100% - 左侧40% = 60% */
      width: 60%;
      height: 300px;
    }
  </style>
</head>

<body>
  <div class="panelSection" id="queryZone">
    <div class="easyui-panel " title="查询区域" style="padding:3px 3px 5px;"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <div>
        <div class="inline-block">
          <div class="divLabel">主制分厂:</div>
          <select id='ddlFactory' data-options='editable:true' class='easyui-combobox select'
            style="width:160px;"></select>
        </div>

        <div class="inline-block">
          <div class="divLabel">订单号:</div>
          <input id="txtMfgordername" class="easyui-textbox" style="width:200px;" />
        </div>

        <div class="inline-block">
          <div class="divLabel">零件号:</div>
          <input id="txtProductname" class="easyui-textbox" style="width:200px;" />
        </div>
        <button id="btnSearch" class="easyui-linkbutton" data-options="">查 询</button>
        <button id="btnReset" class="easyui-linkbutton" data-options="">重 置</button>
      </div>
    </div>
  </div>

  <div class="container">
    <div class="left">
      <div class="panelSection">
        <div class="easyui-panel " title="订单信息" style="padding: 3px;"
          data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
          <div style="background: #fff; margin: 3px 0px 3px 3px">
            <table id="tbGrid" class="easyui-datagrid" style="height: 300px;" data-options="rownumbers:true">
            </table>
            <div id="pp" style="float: right" class="easyui-pagination" data-options="
              layout:['list','first','prev','next','last','manual','info'],
                total: 0,
                showPageList: true,
                showPageInfo: false,
                showRefresh: false,
                pageList:[10,20,50,100,200],
                afterPageText:'共&nbsp{pages}&nbsp页'">
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="right">
      <div class="panelSection">
        <div class="easyui-panel " title="ERP集件信息" style="padding: 3px;"
          data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
          <div style="background: #fff; margin: 3px 0px 3px 3px">
            <table id="tbErp" class="easyui-datagrid" style="height: 330px;" data-options="rownumbers:true">
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>

  <div class="container" style="margin-top: 10px;">
    <div style="display: inline-block;width: 30%;height: 300px;">
      <div class="panelSection">
        <div class="easyui-panel " title="默认工艺集件信息" style="padding: 3px;"
          data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
          <div style="background: #fff; margin: 3px 0px 3px 3px">
            <table id="tbBom" class="easyui-datagrid" style="height: 330px;" data-options="rownumbers:true">
            </table>
          </div>
        </div>
      </div>
    </div>
    <div style="display: inline-block;width: 70%;height: 300px;">
      <div class="panelSection">
        <div class="easyui-panel " title="集件差异信息" style="padding: 3px;"
          data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
          <div style="background: #fff; margin: 3px 0px 3px 3px">
            <table id="tbDiff" class="easyui-datagrid" style="height: 330px;" data-options="rownumbers:true">
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>


  <div style="margin:5px;">
    <button id="btnReSend" class="easyui-linkbutton" data-options="">重 推</button>
  </div>
</body>

</html>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/array.pollyfill.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/dayjs.min.js" type="text/javascript"></script>
<script type="text/javascript">
  /**
   * 创建人：zhunan
   * 日期：2025.9.18
   * 描述：配套单校准
  */
  var page = {
    pagetotal: 0,
    pageNumber: 1,
    pageSize: 10,
    mainUrl: getRootPath() + "/Ashx/ErpSendMESMaterialPageHandler.ashx", //本页面后台路径
    //初始化页面
    init: function () {
      page.bind();
      page.initData(); //初始化页面数据
    },
    // 页面事件绑定
    bind: function () {
      $("#tbGrid").datagrid({
        columns: [[
          { field: 'mfgordername', title: '生产订单', width: 200 },
          { field: 'productname', title: '零件号', width: 100 },
          { field: 'qty', title: '计划数', width: 100 },
          {
            field: 'plannedstartdate', title: '计划开始时间', width: 100,
            formatter: function (value) {
              if (value) {
                return value.split('T')[0];
              } else {
                return "";
              }
            }
          },
          {
            field: 'plannedcompletiondate', title: '计划完成时间', width: 100,
            formatter: function (value) {
              if (value) {
                return value.split('T')[0];
              } else {
                return "";
              }
            }
          }
        ]],
        onLoadSuccess: function (data) {
          $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
            total: page.pagetotal,
            pageSize: page.pageSize,
            pageNumber: page.pageNumber
          });
          customizedEasyuiPagination('pp'); //定制化分页
        },
        // 启用单选模式
        singleSelect: true,
        onCheck: function (rowIndex, rowData) { },
        onClickRow: function (index, row) {
          page.getBom(row.mfgordername);
          page.getErp(row.mfgordername);
          page.getDiff(row.mfgordername);
        }
      });

      $("#tbErp").datagrid({
        columns: [[
          { field: 'specno', title: '工序号', width: 100 },
          { field: 'specname', title: '工序名称', width: 100 },
          { field: 'productname', title: '零件号', width: 160 },
          { field: 'productbatchno', title: '零件批次号', width: 100 },
          { field: 'qty', title: 'ERP订单需求数', width: 100 },
          { field: 'uom', title: '计量单位', width: 80 },
          { field: 'rspos', title: '项目编号', width: 200 }
        ]]
      });

      $("#tbBom").datagrid({
        columns: [[
          { field: 'specno', title: '工序号', width: 80 },
          { field: 'opdesc', title: '工序名称', width: 100 },
          { field: 'productname', title: '零件号', width: 160 },
          { field: 'mesqty', title: 'MES订单需求数', width: 100 }
        ]]
      });

      $("#tbDiff").datagrid({
        columns: [[
          { field: 'specno', title: '工序号', width: 80 },
          { field: 'specname', title: '工序名称', width: 100 },
          { field: 'productname', title: '零件号', width: 180 },
          { field: 'diffqty', title: '差异数', width: 80 },
          { field: 'oper_type', title: '差异类型', width: 100 },
          {
            field: 'createdate', title: '推送时间', width: 160,
            formatter: function (value) {
              if (value) {
                return value.replace('T', ' ');
              } else {
                return "";
              }
            }
          },
          { field: 'send_status', title: '推送状态', width: 80 },
          { field: 'erp_status', title: 'ERP接收状态', width: 80 },
          {
            field: 'erp_return_date', title: 'ERP接收时间', width: 160,
            formatter: function (value) {
              if (value) {
                return value.replace('T', ' ');
              } else {
                return "";
              }
            }
          },
          { field: 'erp_msg', title: 'ERP返回消息', width: 120 }
        ]]
      });

      //分页事件
      $('#pp').pagination({
        onSelectPage: function (pageNumber, pageSize) {
          customizedEasyuiPagination('pp'); //定制化分页
          page.pageSize = pageSize;
          page.pageNumber = pageNumber;
          page.search();
        }
      });

      // 查询
      $("#btnSearch").on("click", function () {
        page.pageNumber = 1;
        page.search();
      });

      // 重置
      $("#btnReset").on('click', function () {
        page.resetData();
      });

      // 重推
      $("#btnReSend").on('click', function () {
        page.resendData();
      });
    },
    // 初始化页面
    initData: function () {
      page.getFactory();
    },
    // 获取分厂列表
    getFactory: function () {
      $.ajax({
        type: "post",
        url: getRootPath() + "/Ashx/ApsHandler/EmployeeMaintPage.ashx?actions=getFactory",
        data: { action: "GetFactory" },
        cashe: false,
        dataType: 'json',
        success: function (res) {
          if (res.Result) {
            // 绑定弹出框分厂下拉框
            $("#ddlFactory").combobox({
              valueField: 'factoryid',
              textField: 'factoryname',
              panelHeight: 200,
              data: res.DBTable
            });

            $.ajax({
              type: "post",
              url: page.mainUrl + "?actions=getUserInfo",
              data: { action: "getUserInfo" },
              cashe: false,
              dataType: 'json',
              success: function (res) {
                if (res.Result) {
                  $("#ddlFactory").combobox('select', res.ReturnData.FactoryID);
                  $('#ddlFactory').combobox('disable');
                } else {
                  displayMessage(res.Message, false);
                }
              }
            });
          }
        }
      });
    },
    // 查询
    search: function () {
      var formData = {
        action: "getMfgorderData",
        pageSize: page.pageSize,
        pageNumber: page.pageNumber,
        factoryid: $('#ddlFactory').combobox('getValue'),//主制分厂
        mfgordername: $("#txtMfgordername").textbox('getValue'),//订单号
        productname: $("#txtProductname").textbox('getValue')//零件号
      };

      $.ajax({
        type: "Post",
        url: page.mainUrl + "?actions=getData",
        data: formData,
        cashe: false,
        async: true,
        beforeSend: function () {
          $('#tbGrid').datagrid('loading');
          $(this).attr("disabled", "disabled"); //禁用按钮
        },
        success: function (data) {
          $('#tbGrid').datagrid('loaded');
          $(this).removeAttr("disabled"); //恢复按钮
          var result = JSON.parse(data);
          if (result.Result) {
            //给分页对象赋值
            page.pagetotal = result.RowCount;
            $('#tbGrid').datagrid('loadData', { total: result.RowCount, rows: result.DBTable });
          } else {
            displayMessage(result.Message, false);
          }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          $('#tbGrid').datagrid('loaded');
          $(this).removeAttr("disabled"); //恢复按钮
          alert(XMLHttpRequest.responseText);
        }
      });
    },
    // 查询bom
    getBom: function (mfgordername) {
      var formData = {
        action: "getBom",
        mfgordername: mfgordername//订单号
      };

      $.ajax({
        type: "Post",
        url: page.mainUrl + "?actions=getBom",
        data: formData,
        cashe: false,
        async: true,
        beforeSend: function () {
          $('#tbBom').datagrid('loading');
          $(this).attr("disabled", "disabled"); //禁用按钮
        },
        success: function (data) {
          $('#tbBom').datagrid('loaded');
          $(this).removeAttr("disabled"); //恢复按钮
          var result = JSON.parse(data);
          $('#tbBom').datagrid('loadData', { rows: result.DBTable });
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          $('#tbBom').datagrid('loaded');
          $(this).removeAttr("disabled"); //恢复按钮
          alert(XMLHttpRequest.responseText);
        }
      });
    },
    // 查询erp推送的bom
    getErp: function (mfgordername) {
      var formData = {
        action: "getErp",
        mfgordername: mfgordername//订单号
      };

      $.ajax({
        type: "Post",
        url: page.mainUrl + "?actions=getErp",
        data: formData,
        cashe: false,
        async: true,
        beforeSend: function () {
          $('#tbErp').datagrid('loading');
          $(this).attr("disabled", "disabled"); //禁用按钮
        },
        success: function (data) {
          $('#tbErp').datagrid('loaded');
          $(this).removeAttr("disabled"); //恢复按钮
          var result = JSON.parse(data);
          $('#tbErp').datagrid('loadData', { rows: result.DBTable });
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          $('#tbErp').datagrid('loaded');
          $(this).removeAttr("disabled"); //恢复按钮
          alert(XMLHttpRequest.responseText);
        }
      });
    },
    // 查询已生成的集件差异信息
    getDiff: function (mfgordername) {
      var formData = {
        action: "getDiff",
        mfgordername: mfgordername//订单号
      };

      $.ajax({
        type: "Post",
        url: page.mainUrl + "?actions=getDiff",
        data: formData,
        cashe: false,
        async: true,
        beforeSend: function () {
          $('#tbDiff').datagrid('loading');
          $(this).attr("disabled", "disabled"); //禁用按钮
        },
        success: function (data) {
          $('#tbDiff').datagrid('loaded');
          $(this).removeAttr("disabled"); //恢复按钮
          var result = JSON.parse(data);
          $('#tbDiff').datagrid('loadData', { rows: result.DBTable });
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          $('#tbDiff').datagrid('loaded');
          $(this).removeAttr("disabled"); //恢复按钮
          alert(XMLHttpRequest.responseText);
        }
      });
    },
    // 重置
    resetData: function () {
      $("#txtMfgordername").textbox('clear');
      $("#txtProductname").textbox('clear');
      $("#tbGrid").datagrid('loadData', { total: 0, rows: [] });
      $("#tbBom").datagrid('loadData', { total: 0, rows: [] });
      $("#tbErp").datagrid('loadData', { total: 0, rows: [] });
      $("#tbDiff").datagrid('loadData', { total: 0, rows: [] });
      page.pageNumber = 1;
      page.pageSize = 10;

      $('#pp').pagination('refresh', { // 改变选项并刷新分页栏信息
        total: 0,
        pageNumber: 1,
        pageSize: 10
      });
    },
    // 重推
    resendData: function () {
      var selectData = $("#tbDiff").datagrid('getRows');
      if (selectData.length === 0) {
        displayMessage("订单还未生成集件差异信息，不能重推", false);
        return;
      }

      if (selectData.some(function (item) { return item.erp_status === '成功' })) {
        displayMessage("集件差异信息已推送成功，不能重推", false);
        return;
      }

      $.messager.confirm('确认', '你确认要重推吗?', function (r) {
        if (r) {
          $.ajax({
            type: "post",
            url: page.mainUrl + "?actions=resendErp",
            data: {
              action: "resendErp",
              postData: JSON.stringify(selectData)
            },
            cashe: false,
            dataType: 'json',
            success: function (res) {
              if (res.Result) {
                displayMessage('重推成功', true);
                page.resetData();
                $('#tbGrid').datagrid('loadData', []);
              } else {
                displayMessage(res.Message, false);
              }
            }
          });
        }
      });
    }
  };

  $(function () {
    page.init();
  });
</script>